home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 2.7 KB | 153 lines | [TEXT/CWIE] |
- /***
- * Created by Bill Hubauer on Fri, Jun 21, 1996 @ 2:53 AM.
- *
- ***/
-
-
- #ifndef __BlasteroidsShipSprite_H__
- #include "BlasteroidsShipSprite.h"
- #endif
-
-
- void CBlasteroidsShipSprite::UpdatePosition() //Override
- {
- if(SpaceDownQ()){
- FireGun();
- }else{
-
- short newHPos = GetLocation()->left;
- short newVPos = GetLocation()->top;
- const Rect& bounds = *GetGameBounds();
-
- if(LeftArrowQ()){
- newHPos -= kMoveHInterval;
- }else if(RightArrowQ()){
- newHPos += kMoveHInterval;
- }
-
- if(newHPos < bounds.left){
- newHPos = bounds.left;
- }else if(newHPos > (bounds.right - Width())){
- newHPos = bounds.right - Width();
- }
-
- if(UpArrowQ()){
- newVPos -= kMoveVInterval;
- }else if(DownArrowQ()){
- newVPos += kMoveVInterval;
- }
-
- if(newVPos < bounds.top){
- newVPos = bounds.top;
- }else if(newVPos > (bounds.bottom - Height())){
- newVPos = bounds.bottom - Height();
- }
-
- MoveBy(newHPos - GetLocation()->left, newVPos - GetLocation()->top);
- }
- }
-
-
- static short CalcShipTop(CSpriteWorld* world)
- {
- const Rect& bounds = *(world->GetSpriteCanvas()->GetBounds());
-
- return (bounds.bottom + bounds.top - 32) / 2;
- }
-
-
- inline short RectWidth(const Rect& r)
- {
- return r.right - r.left;
- }
-
-
- static short CalcShipLeft(CSpriteWorld* world)
- {
- const Rect& bounds = *(world->GetSpriteCanvas()->GetBounds());
-
- return (bounds.left + bounds.right - 32) / 2;
- }
-
-
- CBlasteroidsShipSprite::CBlasteroidsShipSprite(CSpriteWorld* world,CSpriteGame* game)
- : CGameSprite(world, game, 0,game->GetImage(kBaseImageID), CalcShipTop(world),
- CalcShipLeft(world), game->GetImageMask(kBaseImageID))
- {
- }
-
-
- CBlasteroidsShipSprite::~CBlasteroidsShipSprite()//Override
- {
- }
-
-
- Boolean CBlasteroidsShipSprite::LeftArrowQ()
- {
- return KeyIsDownQ(0x7B);
- }
-
-
- Boolean CBlasteroidsShipSprite::RightArrowQ()
- {
- return KeyIsDownQ(0x7C);
- }
-
-
- Boolean CBlasteroidsShipSprite::UpArrowQ()
- {
- return KeyIsDownQ(0x7E);
- }
-
-
- Boolean CBlasteroidsShipSprite::DownArrowQ()
- {
- return KeyIsDownQ(0x7D);
- }
-
-
- Boolean CBlasteroidsShipSprite::SpaceDownQ()
- {
- return KeyIsDownQ(0x31);
- }
-
-
- void CBlasteroidsShipSprite::FireGun()
- {
- short deltaV,deltaH;
-
- deltaV = -75;
- deltaH = 0;
-
- new CBlasteroidsBulletSprite(GetWorld(), GetGame(), GetLocation()->top, GetLocation()->left,
- deltaV, deltaH);
-
- }
-
-
- CBlasteroidsBulletSprite::CBlasteroidsBulletSprite(CSpriteWorld* world,CSpriteGame* game,short startTop,short startLeft,
- short deltaV,short deltaH)
- : CGameSprite(world, game, 0, game->GetImage(kBulletImageID), startTop, startLeft,
- game->GetImageMask(kBulletImageID)),
- fDeltaV(deltaV),
- fDeltaH(deltaH)
- {
-
- }
-
-
- CBlasteroidsBulletSprite::~CBlasteroidsBulletSprite()//Override
-
- {
-
- }
-
-
- void CBlasteroidsBulletSprite::UpdatePosition()//Override
- {
- MoveBy(fDeltaH,fDeltaV);
- if(OutOfBoundsQ()){
- delete this;
- }
- }
-